
package Utilidades;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JLabel;

/**
 *
 * @author lightemp
 */
public class Grafico extends JLabel implements MouseListener {

    private static final long serialVersionUID = -708703562328002253L;
    private BufferedImage grafico;
    private Point p;

    public Grafico() {
        setSize(500, 100);
        p = new Point(0, 0);
        this.addMouseListener(this);
    }



    public void setRuta(String nombreImagen) {
        try {
            grafico = ImageIO.read(getClass().getClassLoader().getResource(nombreImagen));
            repaint();
        } catch (Exception e) {
            System.out.println("No se encontro la imagen");
        }
    }

    @Override
    public void paint(Graphics g) {
        super.paintComponent(g);
        //g.setColor(Color.WHITE);
        //g.fillRect(0, 0, 400, 400);
        if (grafico != null) {
            g.drawImage(grafico, p.x, p.y, getWidth(), getHeight(), this);
            setOpaque(false);
        } else {
            setOpaque(true);
        }

        super.paint(g);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        p.x=e.getX();
        p.y= e.getY();
        this.repaint();
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mousePressed(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseExited(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
